// me/51job/http_get.js

// http://nodejs.cn/api/http.html#http_http_get_url_options_callback

const http = require('http');

let getUrl = 'http://nodejs.cn/index.json';
getUrl = 'https://search.51job.com/list/040000,000000,0000,00,9,99,%25E5%2589%258D%25E7%25AB%25AF,2,1.html?lang=c&postchannel=0000&workyear=99&cotype=99&degreefrom=99&jobterm=99&companysize=99&ord_field=0&dibiaoid=0&line=&welfare=';

http.get(getUrl, (res) => {
    const { statusCode } = res;
    const contentType = res.headers['content-type'];

    let error;
    if (statusCode !== 200) {
        error = new Error(`请求失败\n状态码: ${statusCode}`);
    }

    if (error) {
        console.error(error.message);
        res.resume();
        return;
    }

    res.setEncoding('utf8');
    let rawData = '';
    res.on('data', (chunk) => {
        rawData += chunk;
    });
    res.on('end', ()=>{
        // try{
        //     const parseData = JSON.parse(rawData);
        //     console.log(parseData);
        // }catch(e){
        //     console.error(e.message);
        // }
        console.log(rawData);
    });
}).on('error', (e) => {
    console.error(`出现错误: ${e.message}`);
});



